@layout("/common/_container.html"){
<style>
    .w-e-text-container{
        height: 500px !important;
    }
</style>
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-form form-board" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin">
            <input type="hidden" id="newsId" name="newsId" value="${item.newsId}">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"><span style="color: red;">*</span>分类</label>
                    <div class="layui-input-inline">
                        <select name="categoryId" id="categoryId" lay-verify="required">
                            @for(category in categories){
                                <option value="${category.categoryId}"
                                    @if(category.categoryId == item.categoryId){
                                    selected="" @}
                                >${category.categoryName}</option>
                            @}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-block">
                    <label class="layui-form-label">文章标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="newsName" id="newsName" value="${item.newsName}" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <!--<div class="layui-form-item">
                <div class="layui-block">
                    <label class="layui-form-label">文章首图</label>
                    <div class="layui-input-block">
                        <input type="text" name="newsPic" id="newsPic" value="${item.newsPic}" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>-->
            <div class="layui-form-item">
                <div class="layui-block">
                    <label class="layui-form-label">文章简介</label>
                    <div class="layui-input-block">
                        <input type="text" name="newsDesc" id="newsDesc" value="${item.newsDesc}" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">排序值</label>
                    <div class="layui-input-inline">
                        <input type="text" name="newsNum" id="newsNum" value="${item.newsNum}" lay-verify="number"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-block">
                    <label class="layui-form-label">文章内容</label>
                    <div class="layui-input-block">
                        <div id="newsDetails" style="height:500px;"></div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" lay-submit="" lay-filter="news-submit">提交</button>
                        <button class="layui-btn layui-btn-primary layuiadmin-btn-useradmin" data-type="newsCancel">取消</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script src="${ctxPath}/static/wangEditor/wangEditor.js"></script>
<script>
  layui.config({
	 base: Feng.ctxPath + '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form','laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,laydate = layui.laydate;

      var E = window.wangEditor
      //var editor = new E('#editor')
      var editor = new E( document.getElementById('newsDetails') )
      editor.customConfig.uploadImgServer = Feng.ctxPath +'/news/toUploadImage/';
      editor.customConfig.uploadFileName = 'uploadImage';
      editor.customConfig.customAlert = function (info) {
          // info 是需要提示的内容
          Feng.error('上传图片提示：' + info)
      }
      editor.create()
      editor.txt.html('${item.newsDetails}');

      //事件
      var active = {
          //取消
          newsCancel: function(){
              var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
              location.href = Feng.ctxPath + '/news';
          }
      };

      $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
      });

      /* 监听提交 */
      form.on('submit(news-submit)', function(data){
          var field = data.field;
          //获取富文本内容
          field.newsDetails = editor.txt.html();

          var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 ,shade: 0.01});
          $.ajax({
              type : "post",  //提交方式
              url : Feng.ctxPath + "/news/update",//路径
              dataType:"json",
              contentType: "application/json",
              data:JSON.stringify(field),
              success : function(data) {//返回数据根据结果进行相应的处理
                  if (data.code == 0){
                      Feng.success("更新成功!");
                      window.setTimeout(function () {
                          location.href = Feng.ctxPath + '/news';
                          layer.close(loadingIndex); //关闭弹层
                      }, 1500);
                  }else{
                      Feng.error("更新失败!" + data.responseJSON.message + "!");
                      layer.close(loadingIndex); //关闭弹层
                  }
              }
          });
          return false;
      });
  })
  </script>
@}

